package com.kingdee.eas.xbang.contract.app;

import org.apache.log4j.Logger;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.framework.BillBaseException;
import com.kingdee.eas.xbang.contract.BillStatusEnum;
import com.kingdee.eas.xbang.contract.ContractFacadeFactory;
import com.kingdee.eas.xbang.contract.ContractFactory;
import com.kingdee.eas.xbang.contract.ContractInfo;

public class ContractControllerBean extends AbstractContractControllerBean {
	private static Logger logger = Logger.getLogger("com.kingdee.eas.xbang.contract.app.ContractControllerBean");

	protected void _passAudit(Context ctx, IObjectPK pk, IObjectValue model) throws EASBizException, BOSException {
		// super._passAudit(ctx, pk, model);
		if (model == null){
			model = ContractFactory.getLocalInstance(ctx).getContractInfo(pk);
		}
		if (model instanceof ContractInfo) {
			ContractInfo coreBillBaseInfo = (ContractInfo) model;
			coreBillBaseInfo.setBillStatus(BillStatusEnum.audited);
			super.update(ctx, pk, coreBillBaseInfo);
			if (super._isExistPropertyName(ctx, coreBillBaseInfo, "CheckedStatus")) {
				coreBillBaseInfo.setInt("CheckedStatus", 2);
				if (coreBillBaseInfo.getId() == null)
					throw new BillBaseException(BillBaseException.NOEXIST);

			}
			ContractFacadeFactory.getLocalInstance(ctx).terminationContract(pk);
		}
	}

	protected IObjectPK _submit(Context ctx, IObjectValue model) throws BOSException, EASBizException {
		IObjectPK pk = super._submit(ctx, model);
		if (model instanceof ContractInfo) {
			ContractInfo coreBillBaseInfo = (ContractInfo) model;
			coreBillBaseInfo.setBillStatus(BillStatusEnum.auditing);
			super.update(ctx, pk, coreBillBaseInfo);
			ContractFacadeFactory.getLocalInstance(ctx).terminationContract(pk);
		}

		return pk;

	}

}
